﻿Imports GUI
Imports DAO
Public Class frmChiTietPhieuKhamBenh
    Private dt_maphieu As New DataTable
    Private dt_mathuoc As New DataTable
    Private dt_madonvi As New DataTable
    Private dt_cachdung As New DataTable
    Private dt_mabenh As New DataTable
    Private maphieu As Long
    Private mathuoc As Long
    Private madonvi As Long
    Private soluong As Long
    Private cachdung As Long
    Private mabenh As Long
    Private Sub frmChiTietPhieuKhamBenh_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'hien thi ma phieu
        Dim pkb As New PhieuKhamBenhDAO()
        dt_maphieu = pkb.LayMaPhieu()
        For i As Integer = 0 To dt_maphieu.Rows.Count - 1
            cbbmaphieu.Items.Add(dt_maphieu.Rows(i)("MaPhieu").ToString() + ":" + dt_maphieu.Rows(i)("HoTen").ToString())

        Next
        cbbmaphieu.SelectedIndex = dt_maphieu.Rows.Count - 1
        'hien thi ma thuoc

        dt_mathuoc = pkb.LayLoaiThuoc()
        For i As Integer = 0 To dt_mathuoc.Rows.Count - 1
            cbbmathuoc.Items.Add(dt_mathuoc.Rows(i)("MaThuoc").ToString() + ":" + dt_mathuoc.Rows(i)("TenThuoc").ToString())

        Next
        'hien thi ma don vi

        dt_madonvi = pkb.LayDonVi()
        For i As Integer = 0 To dt_madonvi.Rows.Count - 1
            cbbmadonvi.Items.Add(dt_madonvi.Rows(i)("MaDonVi").ToString() + ":" + dt_madonvi.Rows(i)("TenDonVi").ToString())

        Next
        'hien thi cach dung

        dt_cachdung = pkb.LayCachDung()
        For i As Integer = 0 To dt_cachdung.Rows.Count - 1
            cbbcachdung.Items.Add(dt_cachdung.Rows(i)("MaCachDung").ToString() + ":" + dt_cachdung.Rows(i)("ChiDinh").ToString())

        Next
        'hien thi ma benh

        dt_mabenh = pkb.LayLoaiBenh()
        For i As Integer = 0 To dt_mabenh.Rows.Count - 1
            cbbmabenh.Items.Add(dt_mabenh.Rows(i)("MaBenh").ToString() + ":" + dt_mabenh.Rows(i)("TenBenh").ToString())

        Next
    End Sub

    Private Sub btncapnhat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncapnhat.Click
        If (DialogResult.Yes) Then
            LayDuLieu()
            Dim ctpkb_BUS As New ChiTiet_PKBBUS()
            Dim kq As Integer
            kq = ctpkb_BUS.INSERT(maphieu, mathuoc, madonvi, soluong, cachdung, mabenh)
            If (kq = 2) Then
                MessageBox.Show(" loi~")

            End If
            If (kq = 0) Then
                MessageBox.Show("cap nhat khong thanh cong")

            End If

            If (kq = 1) Then
                MessageBox.Show("cap nhat thanh cong")
            End If
        Else
            Return
        End If
        

    End Sub
    Private Sub LayDuLieu()
        Dim temp As Integer
        'lay ma phieu
        temp = cbbmaphieu.SelectedIndex
        If (temp >= 0) Then
            maphieu = dt_maphieu.Rows(temp)("MaPhieu")
        Else
            MessageBox.Show("Chua chon ma phieu")
            Return
        End If
        'lay ma thuoc
        temp = cbbmathuoc.SelectedIndex
        If (temp >= 0) Then
            mathuoc = dt_mathuoc.Rows(temp)("MaThuoc")
        Else
            MessageBox.Show("Chua chon ma thuoc")
            Return
        End If
        'lay ma don vi
        temp = cbbmadonvi.SelectedIndex
        If (temp >= 0) Then
            madonvi = dt_madonvi.Rows(temp)("MaDonVi")
        Else
            MessageBox.Show("Chua chon ma don vi")
            Return
        End If
        'lay so luong
        Try
            soluong = txtsoluong.Text
        Catch ex As Exception
            MessageBox.Show("So luong phai la so")
            Return
        End Try
        'lay cach dung
        temp = cbbcachdung.SelectedIndex
        If (temp >= 0) Then
            cachdung = dt_cachdung.Rows(temp)("MaCachDung")
        Else
            MessageBox.Show("Chua chon ma cach dung")
            Return
        End If
        'lay ma benh
        temp = cbbmabenh.SelectedIndex
        If (temp >= 0) Then
            mabenh = dt_mabenh.Rows(temp)("MaBenh")
        Else
            MessageBox.Show("Chua chon ma ma benh")
            Return
        End If

    End Sub

    Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter

    End Sub
End Class